﻿using pgnSoft.Veloz.ERP.Models.PageModels;
using pgnSoft.Veloz.ERP.Models.PageModels.PageSections;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Web.Helpers;
using System.Linq;

namespace pgnSoft.Veloz.ERP.Models
{

    public class PageModel
    {
        private System.Web.Mvc.Controller controler;

        public PageModel(System.Web.Mvc.Controller Controler)
        {
            this.controler = Controler;
            Style = new Style(Controler);
            Style.Styles.Add(new PageModels.Style("~/resources/css/bootstrap.css"));  
            Style.Styles.Add(new PageModels.Style("~/resources/css/simple_menu.css"));  
            Script = new Script();
            PageTitle = "Veloz";
            PageSubTitle = "ERP";
            PageBadge = "Inovation";
            PageTitleVisible = false;
            PageSubTitleVisible = false;
            PageBadgeVisible = false;
            PageHeaderImageVisible = false;
            PageLogoURL = "./resources/images/logo/veloz_1_133_38.png";
            PageLogoVisible = false;

            Sections = new List<IPageSection>();
            Sections.Add(new FileViewPageContent() { ViewFilename = "~/Views/Main/_Top.cshtml", RenderOrder = 1 });
            Sections.Add(new FileViewPageContent() { ViewFilename = "~/Views/Main/_Left.cshtml", RenderOrder = 2 });
            Sections.Add(new FileViewPageContent() { ViewFilename = "~/Views/Main/_Center.cshtml", RenderOrder = 3 });
            Thread.CurrentThread.CurrentUICulture = CurrentCultureInfo;
        }

       
        public string PageTitle { get; set; }
        public bool PageTitleVisible { get; set; }
        public string PageSubTitle { get; set; }
        public bool PageSubTitleVisible { get; set; }
        public string PageBadge { get; set; }
        public bool PageBadgeVisible { get; set; }
        public bool PageHeaderImageVisible { get; set; }
        public string PageLogoURL { get; set; }
        public bool PageLogoVisible { get; set; }

        public Style Style { get; set; }
        public Script Script { get; set; }
        public GoogleAnalytics GoogleAnalytics { get; set; }
        public List<IPageSection> Sections { get; set; }

        public CultureInfo DefaultCultureInfo
        {
            get
            {
                return (CultureInfo)controler.Session["user-culture-default-language"];
            }
            set
            {
                controler.Session["user-culture-default-language"] = value;
            }

        }
        public CultureInfo CurrentCultureInfo
        {
            get
            {
                return (CultureInfo)controler.Session["user-culture-current-language"];
            }
            set
            {
                Thread.CurrentThread.CurrentCulture = CurrentCultureInfo;
                Thread.CurrentThread.CurrentUICulture = CurrentCultureInfo;
                controler.Session["user-culture-current-language"] = value;
                Resource = new System.Resources.ResourceManager("pgnSoft.Veloz.ERP.App_GlobalResources.strings", System.Reflection.Assembly.GetExecutingAssembly());
            }
        }

        private ResourceManager _Resource = null;
        public ResourceManager Resource
        {
            get
            {
                if (_Resource == null)
                {
                    CurrentCultureInfo = CurrentCultureInfo;
                }
                if (_Resource.BaseName != CurrentCultureInfo.ToString())
                {
                    CurrentCultureInfo = CurrentCultureInfo;
                }
                return _Resource;
            }
            set
            {
                _Resource = value;
            }
        }


        public List<CultureInfo> UserLanguages {
            get {
                return (List<CultureInfo>)controler.Session["user-culture-languages"];
            }
            set {
                controler.Session["user-culture-languages"] = value;
            }
        }

        public string GetCultureInfoFlagIcon(string cultureInfo)
        {
            return "../resources/images/flags/" +  cultureInfo.ToString().Split('-').LastOrDefault().ToLower()  + ".png";
        }

       
    }




}
